//
//  NearByCell.m
//  QSBK
//
//  Created by Eric Wang on 4/17/15.
//  Copyright (c) 2015 Eric Wang. All rights reserved.
//
#import "Common.h"
#import "NearByCell.h"
#define cellH (ScreenH-StatusBarH-60)/6
@implementation NearByCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        [self addAllSubViews];
    }
    return self;
}


- (void)addAllSubViews
{
    self.headImageView = [[UIImageView alloc]init];
    self.headImageView.translatesAutoresizingMaskIntoConstraints = NO;
    
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.font = [UIFont systemFontOfSize:14];
    self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
    
    
    self.cellDetailLabel = [[UILabel alloc]init];
    self.cellDetailLabel.font = [UIFont systemFontOfSize:12];
    self.cellDetailLabel.translatesAutoresizingMaskIntoConstraints = NO;
    
    self.noticeImageView = [[UIImageView alloc]init];
    self.noticeImageView.hidden = YES;
    self.noticeImageView.translatesAutoresizingMaskIntoConstraints = NO;
    
    
    self.specialImageView = [[UIImageView alloc]init];
    self.specialImageView.hidden = YES;
    self.specialImageView.translatesAutoresizingMaskIntoConstraints = NO;
    
    
    [self.contentView addSubview:self.headImageView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.cellDetailLabel];
    [self.contentView addSubview:self.noticeImageView];
    [self.contentView addSubview:self.specialImageView];
    
    _Constraint = [[NSMutableArray alloc]init];
    
    [_Constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[headImageView(cellH)]-(>=0)-|" options:0 metrics:@{@"cellH":@(cellH)} views:@{@"headImageView":self.headImageView}]];
    [_Constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[headImageView]-0-|" options:0 metrics:nil views:@{@"headImageView":self.headImageView}]];
    
    [_Constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[headImageView]-10-[titleLabel(80)]-(>=0)-|" options:0 metrics:nil views:@{@"headImageView":self.headImageView,@"titleLabel":self.titleLabel}]];
    [_Constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[titleLabel(20)]-(>=0)-|" options:0 metrics:nil views:@{@"titleLabel":self.titleLabel}]];
    
    
    [_Constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[headImageView]-10-[cellDetailLabel(170)]-(>=0)-|" options:0 metrics:nil views:@{@"headImageView":self.headImageView,@"cellDetailLabel":self.cellDetailLabel}]];
    [_Constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-45-[cellDetailLabel(15)]-(>=0)-|" options:0 metrics:nil views:@{@"cellDetailLabel":self.cellDetailLabel}]];
    
    
    [_Constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[titleLabel]-0-[noticeImageView(15)]-(>=0)-|" options:0 metrics:nil views:@{@"titleLabel":self.titleLabel,@"noticeImageView":self.noticeImageView}]];
    [_Constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-22.5-[noticeImageView(15)]-(>=0)-|" options:0 metrics:nil views:@{@"noticeImageView":self.noticeImageView}]];
    
    
    
    
    
    [_Constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[titleLabel]-100-[specialImageView(20)]-(>=0)-|" options:0 metrics:nil views:@{@"specialImageView":self.specialImageView,@"titleLabel":self.titleLabel}]];
    [_Constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[specialImageView(20)]-(>=0)-|" options:0 metrics:nil views:@{@"specialImageView":self.specialImageView}]];
    
    
    
    
    
    [self.contentView addConstraints:_Constraint];
    
    
}

-(void)setNearBy:(NearBy *)nearBy
{
    _nearBy = nearBy;
    self.headImageView.image = [UIImage imageNamed:nearBy.imageName];
    self.titleLabel.text = nearBy.title;
    self.cellDetailLabel.text = nearBy.detail;
    
    self.specialImageView.image = [UIImage imageNamed:@"found_ic_new_tips.png"];
    self.noticeImageView.image = [UIImage imageNamed:@"new_msg_tips.9.png"];
}
@end
